package com.landscope.issue.exception;

/**
 * 全局异常
 * @author qzp
 * @version v1.0
 * @date 2021/6/28 10:20
 **/
public class BizException extends RuntimeException {

    private int code;

    private String msg;

    private BizException(int code, String msg, Throwable cause) {
        super(msg, cause);
        this.code = code;
        this.msg = msg;
    }

    public BizException(int code, String msg) {
        this(code, msg, null);
        this.code = code;
        this.msg = msg;
    }

    public BizException() {
    }

    public static BizException noLoginException(String msg) {
        return new BizException(E_EXCEPTION_TYPE.user_token_invalid.getValue(), msg);
    }

    public static BizException noLoginException() {
        return new BizException(E_EXCEPTION_TYPE.user_token_invalid.getValue(), E_EXCEPTION_TYPE.user_token_invalid.getName());
    }

    public static BizException fail(E_EXCEPTION_TYPE e_exception_type) {
        return new BizException(e_exception_type.getValue(), e_exception_type.getName());
    }

    public static BizException fail(String msg) {
        return new BizException(-1, msg);
    }

    public static BizException fail(String msg, int code) {
        return new BizException(code, msg);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }


}
